﻿Shader "GJ/Heatmap2"
{
    Properties
    {
        [PerRendererData] _MainTex("MainTex",2D) = "white"{}
        _LowColor("LowColor",Color) = (1,1,1,1)
        _HighColor("HighColor",Color) = (1,1,1,1)
        _Alpha("Alpha",Range(0,1)) = 0
    }

    SubShader
    {
        Tags {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
        }
        Cull Off Lighting Off ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 2.0

            #include "UnityCG.cginc"

            sampler2D _MainTex;

            float4 _MainTex_ST;
            fixed4 _LowColor;
            fixed4 _HighColor;
            float _Alpha;

            float Normalization(float min, float max, float v)
			{
			    return (v - min) / (max - min);
			}

            struct a2v
            {
                float4 vertex : POSITION;
                fixed4 color  : COLOR;
                float2 uv     : TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2f
            {
                float4 vertex   : SV_POSITION;
                fixed4 color    : COLOR;
                float2 uv       : TEXCOORD0;
                UNITY_VERTEX_OUTPUT_STEREO
            };

            v2f vert(a2v v)
            {
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.color = v.color;
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;
            }

            fixed4 frag(v2f i) : SV_TARGET
            {
                fixed4 tex = tex2D(_MainTex, i.uv);
                fixed4 col;
                if (tex.a == 0)
                    col.a = 0;
                else
                    col = lerp(_LowColor, _HighColor, tex.a);
                col.a = col.a > 0 ? _Alpha : 0;
                return col;
            }

            ENDCG
        }
    }
}
